package io.renren.modules.pms.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.pms.entity.GoodsStockEntity;
import io.renren.modules.pms.service.GoodsStockService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 商品库存表

 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2024-08-13 18:52:54
 */
@RestController
@RequestMapping("pms/goodsstock")
public class GoodsStockController {
    @Autowired
    private GoodsStockService goodsStockService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("pms:goodsstock:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsStockService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("pms:goodsstock:info")
    public R info(@PathVariable("id") Integer id){
        GoodsStockEntity goodsStock = goodsStockService.getById(id);

        return R.ok().put("goodsStock", goodsStock);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("pms:goodsstock:save")
    public R save(@RequestBody GoodsStockEntity goodsStock){
        goodsStockService.save(goodsStock);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("pms:goodsstock:update")
    public R update(@RequestBody GoodsStockEntity goodsStock){
        ValidatorUtils.validateEntity(goodsStock);
        goodsStockService.updateById(goodsStock);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("pms:goodsstock:delete")
    public R delete(@RequestBody Integer[] ids){
        goodsStockService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
